package s47.dqj.dao;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import s47.dqj.bean.FactDepartmentDateDetail;

/**
 * 7-1.科室人员实际上班详情表
 * @author Administrator
 *
 */
@Repository("factDepartmentDateDetailDaoImpl")
public class FactDepartmentDateDetailDaoImpl extends HibernateDaoSupport implements FactDepartmentDateDetailDaoInf{
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#setSupperSessionFactory(org.hibernate.SessionFactory)
	 */
	@Override
	@Resource(name="sessionFactory")
	public void setSupperSessionFactory(SessionFactory sessionFactory){
		super.setSessionFactory(sessionFactory);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#findAllByDdid(s47.dqj.bean.FactDepartmentDateDetail)
	 */
	@Override
	public List<FactDepartmentDateDetail> findAllByDdid(FactDepartmentDateDetail factDepartmentDateDetail){
		String hql="from FactDepartmentDateDetail as fddd where fddd.ddid="+factDepartmentDateDetail.getDdid();
		return getHibernateTemplate().find(hql);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#findAllByCondition(java.lang.String, java.lang.Integer)
	 */
	@Override
	public List<FactDepartmentDateDetail> findAllByCondition(String hql, Integer pageNum){
		Query query=getSession().createQuery(hql);
		query.setFirstResult((Integer.valueOf(pageNum)-1)*10);
		query.setMaxResults(10);
		return query.list();
	}
	
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#selectPageTotal(java.lang.String)
	 */
	@Override
	public List<Integer> selectPageTotal(String tempHQL){
		List<Integer> pageTotal=new ArrayList<Integer>();
		int p;
		Long temp;
		String hql="select Count(*) from FactDepartmentDateDetail as fddd"+tempHQL;
		Query query=getSession().createQuery(hql);
		temp=(Long)query.uniqueResult();
		
		if(temp%10!=0)
			p=(int)(temp/10+1);
		else
			p=(int)(temp/10);
		for(int n=0;n<p;n++){
			pageTotal.add(n+1);
		}
		return pageTotal;
	} 
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#save(s47.dqj.bean.FactDepartmentDateDetail)
	 */
	@Override
	public void save(FactDepartmentDateDetail factDepartmentDateDetail){
		getHibernateTemplate().save(factDepartmentDateDetail);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#update(s47.dqj.bean.FactDepartmentDateDetail)
	 */
	@Override
	public void update(FactDepartmentDateDetail factDepartmentDateDetail){
		getHibernateTemplate().update(factDepartmentDateDetail);
	}
	/* (non-Javadoc)
	 * @see s47.dqj.dao.FactDepartmentDateDetailDaoInf#delete(s47.dqj.bean.FactDepartmentDateDetail)
	 */
	@Override
	public void delete(FactDepartmentDateDetail factDepartmentDateDetail){
		getHibernateTemplate().delete(factDepartmentDateDetail);
	}
}
